<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich">

<ui:composition>
	<h:form id="form">
		<a4j:queue requestDelay="500" ignoreDupResponses="true"/>

		<h:panelGrid columns="2" columnClasses="top , top">
			<rich:extendedDataTable value="#{companyBean.itemsDataModel}"
				var="record" id="table" style="width: 580px; height: 290px;"
				sortMode="#{companyBean.sortMode}"
				sortPriority="#{companyBean.sortPriorities}"
				selectionMode="#{companyBean.selectionMode}"
				selection="#{companyBean.selection}" rows="50"
				>

				<a4j:ajax execute="@form" event="selectionchange"
					listener="#{companyBean.selectionListener}"
					render=":companyBean_selectiontable" />

            	<f:facet name="noData">
                	Nothing found
            	</f:facet>

				<ui:include src="/templates/include/jpaColumn.xhtml">
					<ui:param name="bean" value="#{companyBean}" />
					<ui:param name="beanData" value="#{record.name}" />
					<ui:param name="property" value="name" />
					<ui:param name="headerText"
						value="#{bundle['entities.company.name']}" />
					<ui:param name="textFilterRendered" value="true"/>
					<ui:param name="columnWidth" value="325px;" />
				</ui:include>

				<ui:include src="/templates/include/jpaColumn.xhtml">
					<ui:param name="bean" value="#{companyBean}" />
					<ui:param name="beanData" value="#{record.ico}" />
					<ui:param name="property" value="ico" />
					<ui:param name="headerText"
						value="#{bundle['entities.company.ico']}" />
					<ui:param name="textFilterRendered" value="true"/>
					<ui:param name="columnWidth" value="250px;" />
				</ui:include>
			</rich:extendedDataTable>
			<h:panelGroup layout="block" style="width:500px">
				<rich:panel>
					<f:facet name="header">
						<h:outputText value="#{bundle['windows.sortSelectionModes.title']}" />
					</f:facet>
					<h:panelGrid columns="2">
						<!--
						<h:outputText value="#{bundle['windows.sortSelectionModes.sortMode']}" />
						<rich:select value="#{companyBean.sortMode}" defaultLabel="#{bundle['windows.sortSelectionModes.selectionMode.Multi']}">
							<a4j:ajax execute="@form" event="selectitem" render=":table"/>

							<f:selectItem itemLabel="#{bundle['windows.sortSelectionModes.sortMode.Single']}" itemValue="single" />
							<f:selectItem itemLabel="#{bundle['windows.sortSelectionModes.sortMode.Multi']}" itemValue="multiple" />
						</rich:select>
						-->
						<h:outputText value="#{bundle['windows.sortSelectionModes.selectionMode']}" />
						<rich:select value="#{companyBean.selectionMode}" defaultLabel="#{bundle['windows.sortSelectionModes.selectionMode.Multi']}">
							<a4j:ajax execute="@form" event="selectitem" render=":table"/>

							<f:selectItem itemLabel="#{bundle['windows.sortSelectionModes.selectionMode.Single']}" itemValue="single" />
							<f:selectItem itemLabel="#{bundle['windows.sortSelectionModes.selectionMode.Multi']}" itemValue="multiple" />
							<f:selectItem itemLabel="#{bundle['windows.sortSelectionModes.selectionMode.None']}" itemValue="none" />
						</rich:select>
					</h:panelGrid>
				</rich:panel>
			    <rich:panel>
			        <f:facet name="header">
			            <h:outputText value="#{bundle['windows.entities.company.Actions']}"></h:outputText>
			        </f:facet>
			            <a4j:commandButton action="#{companyBean.removeSelected}" value="#{bundle['entities.removeSelectedRecords']}"  reRender="table,companyBean_selectiontable"/>
			    </rich:panel>
			    <rich:panel>
			        <f:facet name="header">
			            <h:outputText value="#{bundle['windows.entities.company.NewEntity']}"></h:outputText>
			        </f:facet>
			        <h:panelGrid columns="2">
			            <h:outputText value="#{bundle['entities.company.name']}"/>
			            <rich:inplaceInput defaultLabel="click to enter new company name" value="#{companyBean.company.name}" />
			            <h:outputText value="#{bundle['entities.company.ico']}"/>
			            <rich:inplaceInput defaultLabel="click to enter new company registration ID" value="#{companyBean.company.ico}" />
			            <h:outputText value="#{bundle['entities.company.dic']}"/>
			            <rich:inplaceInput defaultLabel="click to enter new company tax ID" value="#{companyBean.company.dic}" />
			            <a4j:commandButton action="#{companyBean.createNew}" value="#{bundle['entities.createNewRecord']}" reRender="table,companyBean_selectiontable"/>
			        </h:panelGrid>
				</rich:panel>
			</h:panelGroup>
		</h:panelGrid>

		<rich:panel>
			<f:facet name="header">
				<h:outputText value="#{bundle['windows.currentlySelected.title']}" />
			</f:facet>
			<rich:dataTable value="#{companyBean.selectionItems}" var="sel"
				id="companyBean_selectiontable" width="100%">
				<rich:column width="100%">
					<h:panelGrid columns="2" columnClasses="top , top" width="100%">
						<rich:panel>
							<f:facet name="header">
								<h:outputText
									value="#{bundle['windows.entities.company.Detail']}"></h:outputText>
							</f:facet>
							<h:panelGrid columns="2" width="100%">
								<h:outputText value="#{bundle['entities.company.name']}" />
								<h:outputText value="#{sel.name}" />
								<h:outputText value="#{bundle['entities.company.ico']}" />
								<h:outputText value="#{sel.ico}" />
								<h:outputText value="#{bundle['entities.company.dic']}" />
								<h:outputText value="#{sel.dic}" />
							</h:panelGrid>
						</rich:panel>
						<h:panelGroup layout="block" style="width:100%">
							<!-- Address -->
							<rich:panel>
								<f:facet name="header">
									<h:outputText
										value="#{bundle['windows.entities.address.Detail']}"></h:outputText>
								</f:facet>
								<h:panelGrid columns="2" width="100%">
									<h:outputText value="#{bundle['entities.address.country']}" />
									<h:outputText value="#{sel.baseAddress.country}" />
									<h:outputText value="#{bundle['entities.address.city']}" />
									<h:outputText value="#{sel.baseAddress.city}" />
									<h:outputText value="#{bundle['entities.address.streetName']}" />
									<h:outputText value="#{sel.baseAddress.streetName}" />
									<h:outputText value="#{bundle['entities.address.zip']}" />
									<h:outputText value="#{sel.baseAddress.zip}" />
								</h:panelGrid>
							</rich:panel>
							<!-- Employee -->
							<rich:panel>
								<f:facet name="header">
									<h:outputText value="#{bundle['windows.entities.employee.Detail']}"></h:outputText>
								</f:facet>
									<rich:dataTable var="entry" value="#{sel.employeesAsList}" width="100%">
										<f:facet name="header">
											<rich:columnGroup>
												<rich:column>
													<h:outputText value="#{bundle['entities.person.firstName']}" />
												</rich:column>
												<rich:column>
													<h:outputText value="#{bundle['entities.person.lastName']}" />
												</rich:column>
												<rich:column>
													<h:outputText value="#{bundle['entities.person.birthDate']}" />
												</rich:column>
												<rich:column>
													<h:outputText value="#{bundle['entities.roleType.code']}" />
												</rich:column>
											</rich:columnGroup>
										</f:facet>
											<rich:column>
												<h:outputText value="#{entry.person.firstName}" />
											</rich:column>
											<rich:column>
												<h:outputText value="#{entry.person.lastName}" />
											</rich:column>
											<rich:column>
												<h:outputText value="#{entry.person.birthDate}" />
											</rich:column>
											<rich:column>
												<rich:list  var="entryRole" value="#{entry.rolesAsList}" type="ordered">
												    <h:outputText value="#{entryRole.roleType.code} - #{entryRole.roleType.name}"/>
												</rich:list>
											</rich:column>
									</rich:dataTable>
							</rich:panel>
							<!-- External worker -->
							<rich:panel>
								<f:facet name="header">
									<h:outputText value="#{bundle['windows.entities.externalWorker.Detail']}"></h:outputText>
								</f:facet>
									<rich:dataTable var="entry" value="#{sel.extWorkersAsList}" width="100%">
										<f:facet name="header">
											<rich:columnGroup>
												<rich:column>
													<h:outputText value="#{bundle['entities.person.firstName']}" />
												</rich:column>
												<rich:column>
													<h:outputText value="#{bundle['entities.person.lastName']}" />
												</rich:column>
												<rich:column>
													<h:outputText value="#{bundle['entities.person.birthDate']}" />
												</rich:column>
												<rich:column>
													<h:outputText value="#{bundle['entities.roleType.code']}" />
												</rich:column>
											</rich:columnGroup>
										</f:facet>
											<rich:column>
												<h:outputText value="#{entry.person.firstName}" />
											</rich:column>
											<rich:column>
												<h:outputText value="#{entry.person.lastName}" />
											</rich:column>
											<rich:column>
												<h:outputText value="#{entry.person.birthDate}" />
											</rich:column>
											<rich:column>
												<rich:list  var="entryRole" value="#{entry.rolesAsList}" type="ordered">
												    <h:outputText value="#{entryRole.roleType.code} - #{entryRole.roleType.name}"/>
												</rich:list>
											</rich:column>
									</rich:dataTable>
							</rich:panel>
						</h:panelGroup>
					</h:panelGrid>
				</rich:column>
			</rich:dataTable>
		</rich:panel>

	</h:form>
</ui:composition>

</html>
